/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.common.web.form;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts.action.ActionForm;

import ar.uba.fi.posgrado.academy.model.Body;
import ar.uba.fi.posgrado.common.model.Role;
import ar.uba.fi.posgrado.common.model.User;

/**
 * @author nicolas.gonzalez
 * 
 */
/**
 * @author pablo
 * 
 */
@SuppressWarnings("serial")
public class UserForm extends ActionForm {

	private String name;

	private String password;

	private String passwordConfirmation;

	/** usado para las listas para realizar operaciones masivas. */
	private String[] selectedItems;

	private String[] selectedRoles;

	private List<User> users = new ArrayList<User>();

	// Roles que tiene
	private List<Role> actualRoles = new ArrayList<Role>();

	// Roles disponibles
	private List<Role> availableRoles = new ArrayList<Role>();

	private List<Body> bodies = new ArrayList<Body>();

	private String selectedBody;

	/**
	 * String con los roles elegidos separados por ';'. Tener en cuenta q el
	 * delimitador esta en un archivo Javascript, por lo en caso de cambiarlo,
	 * mantener coherencia con el archivo js
	 */
	private String chosenRoles;

	private String realName;

	private String surname;

	private Body body;

	/**
	 * @return the bodies
	 */
	public List<Body> getBodies() {
		return bodies;
	}

	/**
	 * @param bodies
	 *            the bodies to set
	 */
	public void setBodies(List<Body> bodies) {
		this.bodies = bodies;
	}

	/**
	 * @return the body
	 */
	public Body getBody() {
		return body;
	}

	/**
	 * @param body
	 *            the body to set
	 */
	public void setBody(Body body) {
		this.body = body;
	}

	public void clearForNew() {
		this.setName("");
		this.setPassword("");
		this.setPasswordConfirmation("");
		this.setActualRoles(new ArrayList<Role>());
		this.setRealName("");
		this.setSurname("");
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return this.password;
	}

	/**
	 * @param password
	 *            the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * @return the selectedItems
	 */
	public String[] getSelectedItems() {
		return this.selectedItems;
	}

	/**
	 * @param selectedItems
	 *            the selectedItems to set
	 */
	public void setSelectedItems(String[] selectedItems) {
		this.selectedItems = selectedItems;
	}

	/**
	 * @return the selectedRoles
	 */
	public String[] getSelectedRoles() {
		return this.selectedRoles;
	}

	/**
	 * @param selectedRoles
	 *            the selectedRoles to set
	 */
	public void setSelectedRoles(String[] selectedRoles) {
		this.selectedRoles = selectedRoles;
	}

	/**
	 * @return the users
	 */
	public List<User> getUsers() {
		return this.users;
	}

	/**
	 * @param users
	 *            the users to set
	 */
	public void setUsers(List<User> users) {
		this.users = users;
	}

	/**
	 * @return the actualRoles
	 */
	public List<Role> getActualRoles() {
		return this.actualRoles;
	}

	/**
	 * @param actualRoles
	 *            the actualRoles to set
	 */
	public void setActualRoles(List<Role> actualRoles) {
		this.actualRoles = actualRoles;
	}

	/**
	 * @return the availableRoles
	 */
	public List<Role> getAvailableRoles() {
		return this.availableRoles;
	}

	/**
	 * @param availableRoles
	 *            the availableRoles to set
	 */
	public void setAvailableRoles(List<Role> availableRoles) {
		this.availableRoles = availableRoles;
	}

	/**
	 * @return the chosenRoles
	 */
	public String getChosenRoles() {
		return this.chosenRoles;
	}

	/**
	 * @param chosenRoles
	 *            the chosenRoles to set
	 */
	public void setChosenRoles(String chosenRoles) {
		this.chosenRoles = chosenRoles;
	}

	/**
	 * @return Devuelve los roles elegidos en una lista de {@link String}
	 */
	public List<String> getChosenRolesAsList() {
		List<String> response = new ArrayList<String>();

		if (chosenRoles.trim().equals(""))
			return response;

		String[] aux = this.chosenRoles.split(";");
		for (int i = 0; i < aux.length; i++) {
			response.add(aux[i]);
		}

		return response;
	}

	/**
	 * @return the passwordConfirmation
	 */
	public String getPasswordConfirmation() {
		return this.passwordConfirmation;
	}

	/**
	 * @param passwordConfirmation
	 *            the passwordConfirmation to set
	 */
	public void setPasswordConfirmation(String passwordConfirmation) {
		this.passwordConfirmation = passwordConfirmation;
	}

	/**
	 * @return the realName
	 */
	public String getRealName() {
		return this.realName;
	}

	/**
	 * @param realName
	 *            the realName to set
	 */
	public void setRealName(String realName) {
		this.realName = realName;
	}

	/**
	 * @return the surname
	 */
	public String getSurname() {
		return this.surname;
	}

	/**
	 * @param surname
	 *            the surname to set
	 */
	public void setSurname(String surname) {
		this.surname = surname;
	}

	/**
	 * @return the selectedBody
	 */
	public String getSelectedBody() {
		return selectedBody;
	}

	/**
	 * @param selectedBody
	 *            the selectedBody to set
	 */
	public void setSelectedBody(String selectedBody) {
		this.selectedBody = selectedBody;
	}

}
